package com.lms.controller;

import com.alibaba.fastjson.JSON;
import com.lms.entity.Dormbuildbaseinfo;
import com.lms.mapper.DormbuildbaseinfoMapper;
import com.lms.service.DormbuildbaseinfoService;
import com.lms.vo.DataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;


/**
 * @Description: 宿舍楼宇后勤基础信息台账控制器类
 * @author: L-B-S
 * @Date: 2021/3/8 9:11
 * @modified_By:
 * @Version: 0.0$
 */
@Controller
public class DormbuildbaseinfoController {

    @Autowired
    private DormbuildbaseinfoService dormbuildbaseinfoService;

    @Autowired
    private DormbuildbaseinfoMapper dormbuildbaseinfoMapper;

    @ResponseBody
    @GetMapping(value = "/dbbi_relax/getList")
    public DataVo<Dormbuildbaseinfo> dbbiList(Integer page, Integer limit) {
        return dormbuildbaseinfoService.getList(page, limit);
    }

    @ResponseBody
    @GetMapping(value = "/wx_dbbi_relax/getList")
    public List<Dormbuildbaseinfo> wxList() {
        return dormbuildbaseinfoMapper.selectList(null);
    }

    @ResponseBody
    @PostMapping(value = "/dbbi_relax/delDbbis")
    public DataVo<Dormbuildbaseinfo> delOnes(@RequestParam(value = "dbbiList") String dbbiList) {
        List<Dormbuildbaseinfo> data = JSON.parseArray(dbbiList, Dormbuildbaseinfo.class);
        return dormbuildbaseinfoService.delDbbis(data);
    }

    @ResponseBody
    @PostMapping(value = "/dbbi_relax/delOne")
    public DataVo<Dormbuildbaseinfo> delOneTran(@RequestParam(value = "dormbuildbaseinfo") String dormbuildbaseinfo) {
        Dormbuildbaseinfo data = JSON.parseObject(dormbuildbaseinfo, Dormbuildbaseinfo.class);
        return dormbuildbaseinfoService.delOne(data);
    }

    @ResponseBody
    @PostMapping(value = "/dbbi_relax/add")
    public DataVo<Dormbuildbaseinfo> addOne(Dormbuildbaseinfo dormbuildbaseinfo) {
        return dormbuildbaseinfoService.addOne(dormbuildbaseinfo);
    }

    @ResponseBody
    @PostMapping(value = "/dbbi_relax/edit")
    public DataVo<Dormbuildbaseinfo> edit(Dormbuildbaseinfo dormbuildbaseinfo) {
        return dormbuildbaseinfoService.edit(dormbuildbaseinfo);
    }

    @ResponseBody
    @PostMapping(value = "/dbbi_relax/upload")
    public DataVo<Dormbuildbaseinfo> upload(MultipartFile file) throws IOException {
        return dormbuildbaseinfoService.uploadExcel(file);
    }

    @GetMapping(value = "/dbbi_relax/{url}")
    public String redirect(@PathVariable("url") String url) {
        return "dbbi_relax/" + url;
    }
}
